from matplotlib import pyplot
from math import pi
import rospy
from sensor_msgs.msg import LaserScan

def show_scan(scan):
    data = scan.ranges
    angles = list(range(-179, 181, 1))

    for i in range(len(data)):
        angles[i] = angles[i] / 180 * pi

    pyplot.clf()
    pyplot.polar(angles, data, 'b.', markersize=3)
    ax = pyplot.gca(projection='polar')
    ax.set_rlim(0.0, 10.0)
    
    pyplot.pause(0.001)

rospy.init_node(name='laser_scan_plot')
rospy.loginfo('laser scan plot start.')
rospy.Subscriber('scan', LaserScan, show_scan, queue_size=1)
rospy.spin()